<!DOCTYPE HTML>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport"
		content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title>意见反馈</title>
	<link rel="stylesheet" type="text/css" href="../../css/api.css" />
	<style>
		#app .header {
			padding: 0 15px;
			height: 44px;
			line-height: 44px;
			text-align: center;
			background-color: #ffffff;
			font-size: 16px;
			position: fixed;
			top: 0;
			right: 0;
			left: 0;
			justify-content: center;
			align-items: center;
			display: flex;
		}

		#app .header img {
			position: absolute;
			left: 15px;
			width: 22px;
			height: 22px;
		}

		#app .content {
			width: 100%;
			padding: 0 15px;
			box-sizing: border-box;
			margin-bottom: 80px;
		}

		#app .info_bt .btn {
			width: 100%;
			height: 60px;
			line-height: 60px;
			text-align: center;
			border-radius: 100px;
			font-size: 16px;
		}

		#app .info_bt .btns_bg {
			background: #fff;
			color: #ff3a24;
			font-weight: bold;
			margin-bottom: 20px;
		}

		#app .info_bt .btns_top {
			background-image: linear-gradient(45deg,
					#ff3a24 0%,
					#ff5340 100%);
			color: #ffffff;
			font-weight: bold;
			margin-bottom: 20px;
		}

		.text_area {
			margin-bottom: 15px;
			position: relative;
		}

		.text_area div.nums {
			position: absolute;
			bottom: 15px;
			right: 15px;
			color: #999;
			font-size: 12px;
		}

		.text_area div.nums span {
			color: #333;
		}

		.text_area textarea {
			width: 100%;
			height: 150px;
			border-radius: 10px;
			background-color: #ffffff;
			padding: 25px;
			box-sizing: border-box;
			font-size: 14px;
			font-weight: bold;
			color: #000;
			line-height: 18px;
		}

		textarea::-webkit-input-placeholder {
			color: #999999;
			font-size: 14px;
			font-weight: 500;
		}

		.sugges_pic {
			display: flex;
			flex-wrap: wrap;
			margin-bottom: 30px;
		}

		.sugges_pic>img {
			display: block;
			margin: 10px 5px;
			width: 100px;
			height: 100px;
			object-fit: cover;
			border-radius: 10px;
		}

		.sugges_pic .no_pic {
			margin: 10px 5px;
			width: 100px;
			height: 100px;
			border-radius: 10px;
			background-color: #fff;
			display: flex;
			align-items: center;
			justify-content: center;
		}

		.sugges_pic .no_pic img {
			width: 30px;
			height: 30px;
		}
	</style>
</head>

<body>
	<div id="app">
		<div class="header">
			<img src="../../image/icon_return.png" alt="" onclick="back()">意见反馈
		</div>
		<div class="content">
			<div class="info_bt">
				<div class="text_area">
					<textarea oninput="changes()" placeholder="请输入反馈意见（最多100字以内）" name="" id="sugges" cols="30"
						rows="10" maxlength="100"></textarea>
					<div class="nums"><span>0</span>/100</div>
				</div>
				<div class="sugges_pic" onclick="hasPerm()">
					<!-- 反馈上传图片 -->
					<div class="no_pic">
						<img src="../../image/feedback_icon_addpictures.png" alt="">
					</div>
				</div>
				<div class="btn btns_bg" onclick="picture()">提交</div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/zepto.js"></script>
<script type="text/javascript">
	var menus;
	var picture_img;
	apiready = function () {
		resume("suggestionFeedback");

		$api.dom('.content').style.paddingTop = $api.fixStatusBar($api.dom('.header')) + 15 + 'px'
	}
	var suggesVal = document.getElementById("sugges");
	function changes() {
		if ($.trim(suggesVal.value).length > 0) {
			$api.addCls($api.dom('.btn'), 'btns_top');
		} else {
			$api.removeCls($api.dom('.btn'), 'btns_top');
		}
		if ($.trim(suggesVal.value).length > 100) {
			api.toast({
				msg: '反馈意见100字以内',
				duration: 2000,
				location: 'middle'
			});
		} else {
			$api.html($api.dom('.nums span'), $.trim(suggesVal.value).length);
		}
	}

	function picture() {
		if ($.trim(suggesVal.value).length > 0) {
			if (picture_img.length != 0) {
				$api.ajax({
					url: 'api/feedback/picture',
					method: 'post',
					data: {
						files: {
							file: picture_img
						}
					}
				}, function (ret) {
					submit(ret.data.path)
				});
			} else {
				submit()
			}
		}
	}
	function submit(path) {
		$api.ajax({
			url: 'api/feedback/submit',
			method: 'post',
			data: {
				values: {
					pic_url: path,
					content: $.trim(suggesVal.value)
				}
			}
		}, function (ret) {
			api.toast({
				msg: "提交成功",
				duration: 3000,
				location: 'middle'
			});
			setTimeout(() => {
				back()
			}, 1000);
		});
	}
	function back() {
		api.closeWin({
		});
	}
	function hasPerm(params) {
		api.requestPermission({
			list: ['storage-w'],
			code: 1
		}, function (ret, err) {
			if (ret.list[0].granted) {
				api.getPicture({
					sourceType: 'library',
					encodingType: 'jpg',
					mediaValue: 'pic',
					destinationType: 'url',
					quality: 50,
				}, function (ret, err) {
					if (ret) {
						if (ret.data) {
							picture_img = ret.data;
							$api.html($api.dom(".sugges_pic"), '<img src="' + ret.data + '" alt="">');
						}
					} else {
						api.toast({
							msg: "上传失败请重试",
							duration: 3000,
							location: 'middle'
						});
					}
				});
			}
		});
	}

</script>

</html>
